/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.aionemu.gameserver.network.aion.serverpackets;

import java.util.Collection;

import com.aionemu.gameserver.model.gameobjects.Item;
import com.aionemu.gameserver.model.templates.item.ItemTemplate;
import com.aionemu.gameserver.network.aion.GameClient;

/**
 * @author Mr. Poke
 *
 */
public class SM_REPURCHASE extends _InventoryPacket
{
	private int			targetObjectId;
	private Collection<Item>	items;

	/**
	 * @param collection
	 */
	public SM_REPURCHASE(Collection<Item> items, int targetObjectId)
	{
		this.items = items;
		this.targetObjectId = targetObjectId;
	}

	@Override
	protected void writeImpl(GameClient client)
	{
		writeD(targetObjectId);
		writeD(1);
		writeH(items.size());

		for (Item item : items)
		{
			writeGeneralInfo(item);

			ItemTemplate itemTemplate = item.getItemTemplate();
			if (itemTemplate.isArmor())
				writeArmorInfo(item, false, false, true);
			else if (itemTemplate.isWeapon())
				writeWeaponInfo(item, false, false, false, true);
			else
				writeGeneralItemInfo(item, false, true);
			writeQ(itemTemplate.getPrice()*item.getItemCount()/5);
		}
	}
}
